<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="../css/mui.min.css" rel="stylesheet" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">扫描过的明信片</h1>
		</header>
		<div class="mui-content">
			<ul id="liData" class="mui-table-view">
			</ul>
		</div>
		<script src="../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/wilddog.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/app.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" charset="utf-8">
			var uid = null;
			 //B页面onload从服务器获取列表数据；
			window.onload = function() {
				//从服务器获取数据
				var authData = ref.getAuth();
				if (authData) {
					uid = authData.uid.substr(authData.uid.indexOf(':') + 1, authData.uid.length);
					console.log("User " + authData.uid + " is logged in with " + authData.provider);
				} else {
					console.log("User is logged out");
				}
				var scandRef = ref.child("scand");
				scandRef.orderByChild("uid").equalTo(uid).on('value', function(snapshot) {
					var liContent = "";
					snapshot.forEach(function(data) {
						liContent += "<li class=\"mui-table-view-cell\" goscens=\"" + data.val().cid + "\">";
						liContent += "						<a href=\"javascript:void(0);\">";
						liContent += "							<div class=\"mui-media-body\">" + data.val().cname + "<\/div>";
						liContent += "						<\/a>";
						liContent += "					<\/li>";
					});
					document.getElementById("liData").innerHTML = liContent;
				});
				//业务数据获取完毕，并已插入当前页面DOM；
				//注意：若为ajax请求，则需将如下代码放在处理完ajax响应数据之后；
				mui.plusReady(function() {
					//关闭等待框
					plus.nativeUI.closeWaiting();
					//显示当前页面
					mui.currentWebview.show();
					// 打开景点
					function gogo(k, aurl, lng, lat, name, cid) {
						mui.openWindow({
							id: 'page_card',
							url: 'card.html',
							show: {
								autoShow: true
							},
							extras: {
								ak: k,
								aurl: aurl,
								lng: lng,
								lat: lat,
								name: name,
								cid: cid
							},
							styles: {
								top: '0px'
							}
						});
					}

					function goscens(cid) {
						var cardsRef = ref.child("cards");
						cardsRef.orderByChild("cid").equalTo(cid).on("value", function(snapshot) {
							console.log("???");
							snapshot.forEach(function(data) {
								gogo(data.val().scensid, data.val().scensurl, data.val().scenslng, data.val().scenslat, data.val().scensname, data.val().cid);
							});
						});
					}
					mui('.mui-table-view').on('tap', '.mui-table-view-cell', function() {
						var gosens = this.getAttribute("goscens");
						goscens(gosens);
					});
				});
			}
		</script>
	</body>

</html>